<?php
class EditLink extends Action {
	/*
	 * (non-PHPdoc) @see Action::execute()
	 */
	public function execute($params) {
		check_login ( ADMIN_LOGIN_PAGE );
		$data = array ();		
		$lid = irqst ( 'lid' );
		$linkM = new WebLinkModel ();
		if (empty ( $lid )) {
			$data ['page_tip_info'] = "<strong>出错啦!</strong>link_id为空，系统无法加载对应友情链接。";
		} else {
			$link = sess_del ( 'link_form_data', false );
			if (! $link) {
				$link = $linkM->read ( $lid );
			}
			if ($link == false) {
				$data ['page_tip_info'] = "<strong>出错啦!</strong>link_id为{$lid}的友情链接不存在。";
			} else {
				$data = $link;
				$data ['page_tip_info'] = sess_del ( 'page_tip_info' );
			}
		}
		$data ['alert_cls'] = 1 == irqst ( 'suc', 0 ) ? 'alert-success' : 'alert-error';
		$data ['error'] = sess_del ( 'link_form_error', array () );
		$data ['error_cls'] = ModelValidator::getErrorCls ( $data ['error'] );
		$data ['editing'] = 1;
		$data ['navi_active'] = '<i class="icon-edit"></i>友情链接';
		
		$types = CoreOptionModel::getOption ( 'link_types' );
		$data ['types'] = ! empty ( $types ) ? array_merge ( array ('未分类' ), explode ( ',', $types ) ) : array ('未分类' );
		
		return new SmartyView ( $data, 'link/LinkForm' );
	}
}